.org 0xE61D8 ; Defense Increase (Direct & Indirect)

Defense_Increase_Direct_Indirect:

	PUSH 	{R4-R6, LR}
	
	MOV		R6, R0
	MOV		R0, R2
	MOV		R5, 0
	
	BL 		Check_Unit_Type
	
	CMP		R0, Unit_Direct_Combat				; Is Unit a Direct?
	BEQ		Skill_Defense_Direct
	
	CMP		R0, Unit_Indirect_Combat			; Is Unit an Indirect?
	BEQ		Skill_Defense_Indirect
	
	B		Skill_Defense_Other

;-------------------------------------------------------------------------------	

Skill_Defense_Direct:

	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R1, [R0, 0]
	
	MOV 	R0, 0x98
	
	ADD		R1, R2, R1, LSL 2
	MUL 	R4, R6, R0
	LDR 	R1, [R1, 0x48]	
	ADD 	R0, R1, 0x5000
	LDR 	R0, [R0, 0xA58]	

	MOV		R1, Rank_Slam_Guard					; Rank: Slam Guard			
	
	ADD		R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped					
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	ADDNE 	R5, R5, 8							; If CO use skill, +8 Direct defense	
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	MOV 	R1, Rank_Slam_Shield				; Rank: Slam Shield
	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R5, R5, 12							; If CO use skill, +12 Direct defense
	
	B		Skill_Defense_Other

;-------------------------------------------------------------------------------	

Skill_Defense_Indirect:

	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R1, [R0, 0]
	
	MOV 	R0, 0x98
	
	ADD		R1, R2, R1, LSL 2
	MUL 	R4, R6, R0
	LDR 	R1, [R1, 0x48]	
	ADD 	R0, R1, 0x5000
	LDR 	R0, [R0, 0xA58]	

	MOV		R1, Rank_Snipe_Guard				; Rank: Snipe Guard		
	
	ADD		R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped					
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV		R1, Rank_Snipe_Shield				; Rank: Snipe Shield
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	ADDNE 	R5, R5, 8							; If CO use skill, +8 Indirect defense	
		
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV		R1, CO_Indirect_Def_1				; Skill: Indirect Defense 1
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	ADDNE 	R5, R5, 12							; If CO use skill, +12 Direct defense	
	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV		R1, CO_Indirect_Def_2				; Skill: Indirect Defense 2
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	ADDNE 	R5, R5, 20							; If CO use skill, +20 Direct defense	
	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	LDR 	R1, [Defense_Increase_Direct_Indirect_1]
	LDR 	R0, [Defense_Increase_Direct_Indirect_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]
	
	MOV		R1, CO_Indirect_Def_3				; Skill: Indirect Defense 3
	
	ADD		R0, R2, R0, LSL 2
	LDR		R0, [R0, 0x48]
	
	ADDNE 	R5, R5, 40							; If CO use skill, +40 Direct defense	
		
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R4
	ADD 	R0, R0, 0x74
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	
	ADDNE 	R5, R5, 80							; If CO use skill, +80 Direct defense	
	
;-------------------------------------------------------------------------------

Skill_Defense_Other:
	
	MOV		R0, R5
	
	POP 	{R4-R6, LR}	
	BX 		LR

;-------------------------------------------------------------------------------		

Defense_Increase_Direct_Indirect_1:
	.dw Reg1_Skill
	
Defense_Increase_Direct_Indirect_2:
	.dw Reg2_Skill



